4 ROS2 - Services , Parameter, Actions

Service-SingleServiceClient.gif
Service-MultipleServiceClient.gif

ROS2 Services

  • Open a new terminal and run:
ros2 run turtlesim turtlesim_node
  • Open another terminal and run:
ros2 run turtlesim turtle_teleop_key
  • Open another terminal and run:
ros2 service list
  • To see service and type together
ros2 service list -t
  • To see the request and response arguments of the /spawn service, run the command:
ros2 interface show turtlesim/srv/Spawn

Pasted image 20251010134419.png

ROS service call

  • Now that you know what a service type is, how to find a service’s type, and how to find the structure of that type’s arguments, you can call a service using:

ros2 service call <service_name> <service_type> <arguments>

ros2 service call /clear std_srvs/srv/Empty

Pasted image 20251010134715.png

ROS2 Param List

  • Open another terminal and run:
ros2 param list

Pasted image 20251010134753.png

ROS2 Param Get

  • To display the type and current value of a parameter, use the command:
    ros2 param get <node_name> <parameter_name>
ros2 param get /turtlesim background_g

Pasted image 20251010134857.png

ROS2 Param Set

  • To change a parameter’s value at runtime, use the command:
    ros2 param set <node_name> <parameter_name> <value>
ros2 param set /turtlesim background_r 150

Pasted image 20251010134953.png

ROS2 Param Dump

  • To save your current configuration of /turtlesim’s parameters, enter the command:
ros2 param dump /turtlesim

Pasted image 20251010135102.png
Pasted image 20251010135108.png

ROS2 Param Load

  • Open another terminal and run:
ros2 param load /turtlesim ./turtlesim.yaml

Pasted image 20251010135205.png

Load Parameter File on Node Startup

  • To start the same node using your saved parameter values, use:
    ros2 run <package_name> <executable_name> --ros-args --params-file <file_name>
ros2 run turtlesim turtlesim_node --ros-args --params-file ./turtlesim.yaml

ROS2 Action

Action-SingleActionClient.gif

  • Open a new terminal and run:
ros2 run turtlesim turtlesim_node
  • Open another terminal and run:
ros2 run turtlesim turtle_teleop_key
  • Open another terminal and run:
ros2 service list

ROS2 Node Info

  • To see the list of actions a node provides, /turtlesim in this case, open a new terminal and run the command:
ros2 node info /turtlesim

Pasted image 20251010135535.png

  • open a new terminal and run the command:
ros2 node info /teleop_turtle

ROS2 Action List

  • Open another terminal and run:
ros2 action list

Pasted image 20251010135631.png

  • Command to show action and node info together:
ros2 action list -t

Pasted image 20251010135649.png

ROS2 Action Info

  • You can further introspect the /turtle1/rotate_absolute action with the command:
ros2 action info /turtle1/rotate_absolute

Pasted image 20251010135727.png

ROS2 Interface Show

  • To show data type together:
ros2 interface show turtlesim/action/RotateAbsolute

Pasted image 20251010140104.png

ROS2 Action send_goal

  • Now let’s send an action goal from the command line with the following syntax:
  • ros2 action send_goal <action_name> <action_type> <values><values> need to be in YAML format.
ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: 1.57}"

Pasted image 20251010140239.png

  • To see the feedback of this goal, add --feedback to the last command you ran
ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: -1.57}" –feedback

Pasted image 20251010140436.png